<?php
// +----------------------------------------------------------------------
// | OpenCMF [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.opencmf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 狂奔的小白兔  1194174530@qq.com
// +----------------------------------------------------------------------
namespace Sport\Admin;
use Admin\Controller\AdminController;
use Common\Util\Think\Page;
/**
 * 留言控制器
 * @author 狂奔的小白兔  1194174530@qq.com
 */
class MessageAdmin extends AdminController {
    /**
     * 默认方法
     * @author 狂奔的小白兔  1194174530@qq.com
     */
    public function index() {

        $keyword   = I('keyword', '', 'string');
        $condition = array('like','%'.$keyword.'%');
        $map['id|uid|yb_nickname|comment'] = array(
            $condition,
            $condition,
            $condition,
            $condition,
            $condition,
            '_multi'=>true
        );

        // 获取所有留言
        $map['status'] = array('egt', '0'); // 禁用和正常状态
        $p = !empty($_GET["p"]) ? $_GET['p'] : 1;
        $user_object = D('Sport/Message');
        $data_list = $user_object
                   ->page($p , C('ADMIN_PAGE_ROWS'))
                   ->where($map)
                   ->order('id desc')
                   ->select();
        $page = new Page(
            $user_object->where($map)->count(),
            C('ADMIN_PAGE_ROWS')
        );

        $builder = new \Common\Builder\ListBuilder();
        $builder->setMetaTitle('留言管理') // 设置页面标题
                ->addTopButton('resume', array('model' => 'sport_message'))  // 添加启用按钮
                ->addTopButton('forbid', array('model' => 'sport_message'))  // 添加禁用按钮
                ->setSearch('请输入ID/易班UID/易班用户名/留言内容', U('index'))
                ->addTableColumn('id', '编号')
                ->addTableColumn('uid', '易班UID')
                ->addTableColumn('yb_nickname', '易班用户名')
                ->addTableColumn('comment', '留言内容')
                ->addTableColumn('is_real', '是否匿名')
                ->addTableColumn('status', '状态', 'status')
                ->addTableColumn('right_button', '操作', 'btn')
                ->setTableDataList($data_list)    // 数据列表
                ->setTableDataPage($page->show()) // 数据列表分页
                ->addRightButton('forbid')        // 添加禁用/启用按钮
                ->display();
    }


}
